home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / MPW / flex 2.4.6 / gen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-21  |  32.6 KB  |  1,478 lines  |  [TEXT/MPS ]

  1. /* gen - actual generation (writing) of flex scanners */
  2.  
  3. /*-
  4.  * Copyright (c) 1990 The Regents of the University of California.
  5.  * All rights reserved.
  6.  *
  7.  * This code is derived from software contributed to Berkeley by
  8.  * Vern Paxson.
  9.  * 
  10.  * The United States Government has rights in this work pursuant
  11.  * to contract no. DE-AC03-76SF00098 between the United States
  12.  * Department of Energy and the University of California.
  13.  *
  14.  * Redistribution and use in source and binary forms are permitted provided
  15.  * that: (1) source distributions retain this entire copyright notice and
  16.  * comment, and (2) distributions including binaries display the following
  17.  * acknowledgement:  ``This product includes software developed by the
  18.  * University of California, Berkeley and its contributors'' in the
  19.  * documentation or other materials provided with the distribution and in
  20.  * all advertising materials mentioning features or use of this software.
  21.  * Neither the name of the University nor the names of its contributors may
  22.  * be used to endorse or promote products derived from this software without
  23.  * specific prior written permission.
  24.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  25.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  26.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27.  */
  28.  
  29. /* $Header: gen.c,v 1.2 94/01/04 14:33:12 vern Exp $ */
  30.  
  31. #include "flexdef.h"
  32.  
  33.  
  34. /* declare functions that have forward references */
  35.  
  36. void gen_next_state PROTO((int));
  37. void genecs PROTO((void));
  38. void indent_put2s PROTO((char [], char []));
  39. void indent_puts PROTO((char []));
  40.  
  41.  
  42. static int indent_level = 0; /* each level is 8 spaces */
  43.  
  44. #define indent_up() (++indent_level)
  45. #define indent_down() (--indent_level)
  46. #define set_indent(indent_val) indent_level = indent_val
  47.  
  48. /* Almost everything is done in terms of arrays starting at 1, so provide
  49.  * a null entry for the zero element of all C arrays.  (The exception
  50.  * to this is that the fast table representation generally uses the
  51.  * 0 elements of its arrays, too.)
  52.  */
  53. static char C_int_decl[] = "static const int %s[%d] =\n    {   0,\n";
  54. static char C_short_decl[] = "static const short int %s[%d] =\n    {   0,\n";
  55. static char C_long_decl[] = "static const long int %s[%d] =\n    {   0,\n";
  56. static char C_state_decl[] =
  57.     "static const yy_state_type %s[%d] =\n    {   0,\n";
  58.  
  59.  
  60. /* Indent to the current level. */
  61.  
  62. void do_indent()
  63.     {
  64.     register int i = indent_level * 8;
  65.  
  66.     while ( i >= 8 )
  67.         {
  68.         putchar( '\t' );
  69.         i -= 8;
  70.         }
  71.  
  72.     while ( i > 0 )
  73.         {
  74.         putchar( ' ' );
  75.         --i;
  76.         }
  77.     }
  78.  
  79.  
  80. /* Generate the code to keep backing-up information. */
  81.  
  82. void gen_backing_up()
  83.     {
  84.     if ( reject || num_backing_up == 0 )
  85.         return;
  86.  
  87.     if ( fullspd )
  88.         indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
  89.     else
  90.         indent_puts( "if ( yy_accept[yy_current_state] )" );
  91.  
  92.     indent_up();
  93.     indent_puts( "{" );
  94.     indent_puts( "yy_last_accepting_state = yy_current_state;" );
  95.     indent_puts( "yy_last_accepting_cpos = yy_cp;" );
  96.     indent_puts( "}" );
  97.     indent_down();
  98.     }
  99.  
  100.  
  101. /* Generate the code to perform the backing up. */
  102.  
  103. void gen_bu_action()
  104.     {
  105.     if ( reject || num_backing_up == 0 )
  106.         return;
  107.  
  108.     set_indent( 3 );
  109.  
  110.     indent_puts( "case 0: /* must back up */" );
  111.     indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
  112.     indent_puts( "*yy_cp = yy_hold_char;" );
  113.  
  114.     if ( fullspd || fulltbl )
  115.         indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
  116.     else
  117.         /* Backing-up info for compressed tables is taken \after/
  118.          * yy_cp has been incremented for the next state.
  119.          */
  120.         indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  121.  
  122.     indent_puts( "yy_current_state = yy_last_accepting_state;" );
  123.     indent_puts( "goto yy_find_action;" );
  124.     putchar( '\n' );
  125.  
  126.     set_indent( 0 );
  127.     }
  128.  
  129.  
  130. /* genctbl - generates full speed compressed transition table */
  131.  
  132. void genctbl()
  133.     {
  134.     register int i;
  135.     int end_of_buffer_action = num_rules + 1;
  136.  
  137.     /* Table of verify for transition and offset to next state. */
  138.     printf( "static const struct yy_trans_info yy_transition[%d] =\n",
  139.         tblend + numecs + 1 );
  140.     printf( "    {\n" );
  141.  
  142.     /* We want the transition to be represented as the offset to the
  143.      * next state, not the actual state number, which is what it currently
  144.      * is.  The offset is base[nxt[i]] - (base of current state)].  That's
  145.      * just the difference between the starting points of the two involved
  146.      * states (to - from).
  147.      *
  148.      * First, though, we need to find some way to put in our end-of-buffer
  149.      * flags and states.  We do this by making a state with absolutely no
  150.      * transitions.  We put it at the end of the table.
  151.      */
  152.  
  153.     /* We need to have room in nxt/chk for two more slots: One for the
  154.      * action and one for the end-of-buffer transition.  We now *assume*
  155.      * that we're guaranteed the only character we'll try to index this
  156.      * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
  157.      * there's room for jam entries for other characters.
  158.      */
  159.  
  160.     while ( tblend + 2 >= current_max_xpairs )
  161.         expand_nxt_chk();
  162.  
  163.     while ( lastdfa + 1 >= current_max_dfas )
  164.         increase_max_dfas();
  165.  
  166.     base[lastdfa + 1] = tblend + 2;
  167.     nxt[tblend + 1] = end_of_buffer_action;
  168.     chk[tblend + 1] = numecs + 1;
  169.     chk[tblend + 2] = 1; /* anything but EOB */
  170.  
  171.     /* So that "make test" won't show arb. differences. */
  172.     nxt[tblend + 2] = 0;
  173.  
  174.     /* Make sure every state has an end-of-buffer transition and an
  175.      * action #.
  176.      */
  177.     for ( i = 0; i <= lastdfa; ++i )
  178.         {
  179.         int anum = dfaacc[i].dfaacc_state;
  180.         int offset = base[i];
  181.  
  182.         chk[offset] = EOB_POSITION;
  183.         chk[offset - 1] = ACTION_POSITION;
  184.         nxt[offset - 1] = anum;    /* action number */
  185.         }
  186.  
  187.     for ( i = 0; i <= tblend; ++i )
  188.         {
  189.         if ( chk[i] == EOB_POSITION )
  190.             transition_struct_out( 0, base[lastdfa + 1] - i );
  191.  
  192.         else if ( chk[i] == ACTION_POSITION )
  193.             transition_struct_out( 0, nxt[i] );
  194.  
  195.         else if ( chk[i] > numecs || chk[i] == 0 )
  196.             transition_struct_out( 0, 0 );    /* unused slot */
  197.  
  198.         else    /* verify, transition */
  199.             transition_struct_out( chk[i],
  200.                         base[nxt[i]] - (i - chk[i]) );
  201.         }
  202.  
  203.  
  204.     /* Here's the final, end-of-buffer state. */
  205.     transition_struct_out( chk[tblend + 1], nxt[tblend + 1] );
  206.     transition_struct_out( chk[tblend + 2], nxt[tblend + 2] );
  207.  
  208.     printf( "    };\n" );
  209.     printf( "\n" );
  210.  
  211. #ifdef MPW
  212.     SpinCursor( 1 );
  213. #endif
  214.     /* Table of pointers to start states. */
  215.     printf(
  216.     "static const struct yy_trans_info *yy_start_state_list[%d] =\n",
  217.         lastsc * 2 + 1 );
  218.     printf( "    {\n" );    /* } so vi doesn't get confused */
  219.  
  220.     for ( i = 0; i <= lastsc * 2; ++i )
  221.         printf( "    &yy_transition[%d],\n", base[i] );
  222.  
  223.     dataend();
  224.  
  225.     if ( useecs )
  226.         genecs();
  227.     }
  228.  
  229.  
  230. /* Generate equivalence-class tables. */
  231.  
  232. void genecs()
  233.     {
  234.     Char clower();
  235.     register int i, j;
  236.     int numrows;
  237.  
  238.     printf( C_int_decl, "yy_ec", csize );
  239.  
  240.     for ( i = 1; i < csize; ++i )
  241.         {
  242.         if ( caseins && (i >= 'A') && (i <= 'Z') )
  243.             ecgroup[i] = ecgroup[clower( i )];
  244.  
  245.         ecgroup[i] = ABS( ecgroup[i] );
  246.         mkdata( ecgroup[i] );
  247.         }
  248.  
  249.     dataend();
  250.  
  251.     if ( trace )
  252.         {
  253.         fputs( "\n\nEquivalence Classes:\n\n", stderr );
  254.  
  255.         numrows = csize / 8;
  256.  
  257.         for ( j = 0; j < numrows; ++j )
  258.             {
  259.             for ( i = j; i < csize; i = i + numrows )
  260.                 {
  261.                 fprintf( stderr, "%4s = %-2d",
  262.                     readable_form( i ), ecgroup[i] );
  263.  
  264.                 putc( ' ', stderr );
  265.                 }
  266.  
  267.             putc( '\n', stderr );
  268.             }
  269.         }
  270.     }
  271.  
  272.  
  273. /* Generate the code to find the action number. */
  274.  
  275. void gen_find_action()
  276.     {
  277.     if ( fullspd )
  278.         indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
  279.  
  280.     else if ( fulltbl )
  281.         indent_puts( "yy_act = yy_accept[yy_current_state];" );
  282.  
  283.     else if ( reject )
  284.         {
  285.         indent_puts( "yy_current_state = *--yy_state_ptr;" );
  286.         indent_puts( "yy_lp = yy_accept[yy_current_state];" );
  287.  
  288.         puts(
  289.         "find_rule: /* we branch to this label when backing up */" );
  290.  
  291.         indent_puts(
  292.         "for ( ; ; ) /* until we find what rule we matched */" );
  293.  
  294.         indent_up();
  295.  
  296.         indent_puts( "{" );
  297.  
  298.         indent_puts(
  299.         "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" );
  300.         indent_up();
  301.         indent_puts( "{" );
  302.         indent_puts( "yy_act = yy_acclist[yy_lp];" );
  303.  
  304.         if ( variable_trailing_context_rules )
  305.             {
  306.             indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" );
  307.             indent_puts( "     yy_looking_for_trail_begin )" );
  308.             indent_up();
  309.             indent_puts( "{" );
  310.  
  311.             indent_puts(
  312.                 "if ( yy_act == yy_looking_for_trail_begin )" );
  313.             indent_up();
  314.             indent_puts( "{" );
  315.             indent_puts( "yy_looking_for_trail_begin = 0;" );
  316.             indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" );
  317.             indent_puts( "break;" );
  318.             indent_puts( "}" );
  319.             indent_down();
  320.  
  321.             indent_puts( "}" );
  322.             indent_down();
  323.  
  324.             indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" );
  325.             indent_up();
  326.             indent_puts( "{" );
  327.             indent_puts(
  328.         "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" );
  329.             indent_puts(
  330.         "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" );
  331.  
  332.             if ( real_reject )
  333.                 {
  334.                 /* Remember matched text in case we back up
  335.                  * due to REJECT.
  336.                  */
  337.                 indent_puts( "yy_full_match = yy_cp;" );
  338.                 indent_puts( "yy_full_state = yy_state_ptr;" );
  339.                 indent_puts( "yy_full_lp = yy_lp;" );
  340.                 }
  341.  
  342.             indent_puts( "}" );
  343.             indent_down();
  344.  
  345.             indent_puts( "else" );
  346.             indent_up();
  347.             indent_puts( "{" );
  348.             indent_puts( "yy_full_match = yy_cp;" );
  349.             indent_puts( "yy_full_state = yy_state_ptr;" );
  350.             indent_puts( "yy_full_lp = yy_lp;" );
  351.             indent_puts( "break;" );
  352.             indent_puts( "}" );
  353.             indent_down();
  354.  
  355.             indent_puts( "++yy_lp;" );
  356.             indent_puts( "goto find_rule;" );
  357.             }
  358.  
  359.         else
  360.         {
  361.         /* Remember matched text in case we back up due to trailing
  362.          * context plus REJECT.
  363.          */
  364.         indent_up();
  365.         indent_puts( "{" );
  366.         indent_puts( "yy_full_match = yy_cp;" );
  367.         indent_puts( "break;" );
  368.         indent_puts( "}" );
  369.         indent_down();
  370.         }
  371.  
  372.         indent_puts( "}" );
  373.         indent_down();
  374.  
  375.         indent_puts( "--yy_cp;" );
  376.  
  377.         /* We could consolidate the following two lines with those at
  378.          * the beginning, but at the cost of complaints that we're
  379.          * branching inside a loop.
  380.          */
  381.         indent_puts( "yy_current_state = *--yy_state_ptr;" );
  382.         indent_puts( "yy_lp = yy_accept[yy_current_state];" );
  383.  
  384.         indent_puts( "}" );
  385.  
  386.         indent_down();
  387.         }
  388.  
  389.     else
  390.         /* compressed */
  391.         indent_puts( "yy_act = yy_accept[yy_current_state];" );
  392.     }
  393.  
  394.  
  395. /* genftbl - generates full transition table */
  396.  
  397. void genftbl()
  398.     {
  399.     register int i;
  400.     int end_of_buffer_action = num_rules + 1;
  401.  
  402.     printf( long_align ? C_long_decl : C_short_decl,
  403.         "yy_accept", lastdfa + 1 );
  404.  
  405.     dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
  406.  
  407.     for ( i = 1; i <= lastdfa; ++i )
  408.         {
  409.         register int anum = dfaacc[i].dfaacc_state;
  410.  
  411.         mkdata( anum );
  412.  
  413. #ifdef MPW
  414.         SpinCursor( 1 );
  415. #endif
  416.         if ( trace && anum )
  417.             fprintf( stderr, "state # %d accepts: [%d]\n",
  418.                 i, anum );
  419.         }
  420.  
  421.     dataend();
  422.  
  423.     if ( useecs )
  424.         genecs();
  425.  
  426.     /* Don't have to dump the actual full table entries - they were
  427.      * created on-the-fly.
  428.      */
  429.     }
  430.  
  431.  
  432. /* Generate the code to find the next compressed-table state. */
  433.  
  434. void gen_next_compressed_state( char_map )
  435. char *char_map;
  436.     {
  437.     indent_put2s( "register YY_CHAR yy_c = %s;", char_map );
  438.  
  439.     /* Save the backing-up info \before/ computing the next state
  440.      * because we always compute one more state than needed - we
  441.      * always proceed until we reach a jam state
  442.      */
  443.     gen_backing_up();
  444.  
  445.     indent_puts(
  446. "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
  447.     indent_up();
  448.     indent_puts( "{" );
  449.     indent_puts( "yy_current_state = (int) yy_def[yy_current_state];" );
  450.  
  451.     if ( usemecs )
  452.         {
  453.         /* We've arrange it so that templates are never chained
  454.          * to one another.  This means we can afford to make a
  455.          * very simple test to see if we need to convert to
  456.          * yy_c's meta-equivalence class without worrying
  457.          * about erroneously looking up the meta-equivalence
  458.          * class twice
  459.          */
  460.         do_indent();
  461.  
  462.         /* lastdfa + 2 is the beginning of the templates */
  463.         printf( "if ( yy_current_state >= %d )\n", lastdfa + 2 );
  464.  
  465.         indent_up();
  466.         indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" );
  467.         indent_down();
  468.         }
  469.  
  470.     indent_puts( "}" );
  471.     indent_down();
  472.  
  473.     indent_puts(
  474. "yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];" );
  475.     }
  476.  
  477.  
  478. /* Generate the code to find the next match. */
  479.  
  480. void gen_next_match()
  481.     {
  482.     /* NOTE - changes in here should be reflected in gen_next_state() and
  483.      * gen_NUL_trans().
  484.      */
  485.     char *char_map = useecs ?
  486.                 "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
  487.                 "YY_SC_TO_UI(*yy_cp)";
  488.  
  489.     char *char_map_2 = useecs ?
  490.                 "yy_ec[YY_SC_TO_UI(*++yy_cp)]" :
  491.                 "YY_SC_TO_UI(*++yy_cp)";
  492.  
  493.     if ( fulltbl )
  494.         {
  495.         indent_put2s(
  496.     "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
  497.                 char_map );
  498.  
  499.         indent_up();
  500.  
  501.         if ( num_backing_up > 0 )
  502.             {
  503.             indent_puts( "{" );    /* } for vi */
  504.             gen_backing_up();
  505.             putchar( '\n' );
  506.             }
  507.  
  508.         indent_puts( "++yy_cp;" );
  509.  
  510.         if ( num_backing_up > 0 )
  511.             /* { for vi */
  512.             indent_puts( "}" );
  513.  
  514.         indent_down();
  515.  
  516.         putchar( '\n' );
  517.         indent_puts( "yy_current_state = -yy_current_state;" );
  518.         }
  519.  
  520.     else if ( fullspd )
  521.         {
  522.         indent_puts( "{" );    /* } for vi */
  523.         indent_puts(
  524.         "register const struct yy_trans_info *yy_trans_info;\n" );
  525.         indent_puts( "register YY_CHAR yy_c;\n" );
  526.         indent_put2s( "for ( yy_c = %s;", char_map );
  527.         indent_puts(
  528.     "      (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" );
  529.         indent_puts( "yy_verify == yy_c;" );
  530.         indent_put2s( "      yy_c = %s )", char_map_2 );
  531.  
  532.         indent_up();
  533.  
  534.         if ( num_backing_up > 0 )
  535.             indent_puts( "{" );    /* } for vi */
  536.  
  537.         indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
  538.  
  539.         if ( num_backing_up > 0 )
  540.             {
  541.             putchar( '\n' );
  542.             gen_backing_up();    /* { for vi */
  543.             indent_puts( "}" );
  544.             }
  545.  
  546.         indent_down();    /* { for vi */
  547.         indent_puts( "}" );
  548.         }
  549.  
  550.     else
  551.         { /* compressed */
  552.         indent_puts( "do" );
  553.  
  554.         indent_up();
  555.         indent_puts( "{" );    /* } for vi */
  556.  
  557.         gen_next_state( false );
  558.  
  559.         indent_puts( "++yy_cp;" );
  560.  
  561.         /* { for vi */
  562.         indent_puts( "}" );
  563.         indent_down();
  564.  
  565.         do_indent();
  566.  
  567.         if ( interactive )
  568.             printf( "while ( yy_base[yy_current_state] != %d );\n",
  569.                 jambase );
  570.         else
  571.             printf( "while ( yy_current_state != %d );\n",
  572.                 jamstate );
  573.  
  574.         if ( ! reject && ! interactive )
  575.             {
  576.             /* Do the guaranteed-needed backing up to figure out
  577.              * the match.
  578.              */
  579.             indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  580.             indent_puts(
  581.                 "yy_current_state = yy_last_accepting_state;" );
  582.             }
  583.         }
  584.     }
  585.  
  586.  
  587. /* Generate the code to find the next state. */
  588.  
  589. void gen_next_state( worry_about_NULs )
  590. int worry_about_NULs;
  591.     { /* NOTE - changes in here should be reflected in get_next_match() */
  592.     char char_map[256];
  593.  
  594.     if ( worry_about_NULs && ! nultrans )
  595.         {
  596.         if ( useecs )
  597.             (void) sprintf( char_map,
  598.                 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
  599.                     NUL_ec );
  600.         else
  601.             (void) sprintf( char_map,
  602.                 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec );
  603.         }
  604.  
  605.     else
  606.         strcpy( char_map, useecs ? "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
  607.                        "YY_SC_TO_UI(*yy_cp)" );
  608.  
  609.     if ( worry_about_NULs && nultrans )
  610.         {
  611.         if ( ! fulltbl && ! fullspd )
  612.             /* Compressed tables back up *before* they match. */
  613.             gen_backing_up();
  614.  
  615.         indent_puts( "if ( *yy_cp )" );
  616.         indent_up();
  617.         indent_puts( "{" );    /* } for vi */
  618.         }
  619.  
  620.     if ( fulltbl )
  621.         indent_put2s(
  622.             "yy_current_state = yy_nxt[yy_current_state][%s];", 
  623.                 char_map );
  624.  
  625.     else if ( fullspd )
  626.         indent_put2s(
  627.             "yy_current_state += yy_current_state[%s].yy_nxt;",
  628.                 char_map );
  629.  
  630.     else
  631.         gen_next_compressed_state( char_map );
  632.  
  633.     if ( worry_about_NULs && nultrans )
  634.         {
  635.         /* { for vi */
  636.         indent_puts( "}" );
  637.         indent_down();
  638.         indent_puts( "else" );
  639.         indent_up();
  640.         indent_puts(
  641.             "yy_current_state = yy_NUL_trans[yy_current_state];" );
  642.         indent_down();
  643.         }
  644.  
  645.     if ( fullspd || fulltbl )
  646.         gen_backing_up();
  647.  
  648.     if ( reject )
  649.         indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  650.     }
  651.  
  652.  
  653. /* Generate the code to make a NUL transition. */
  654.  
  655. void gen_NUL_trans()
  656.     { /* NOTE - changes in here should be reflected in get_next_match() */
  657.     int need_backing_up = (num_backing_up > 0 && ! reject);
  658.  
  659.     if ( need_backing_up )
  660.         /* We'll need yy_cp lying around for the gen_backing_up(). */
  661.         indent_puts( "register char *yy_cp = yy_c_buf_p;" );
  662.  
  663.     putchar( '\n' );
  664.  
  665.     if ( nultrans )
  666.         {
  667.         indent_puts(
  668.             "yy_current_state = yy_NUL_trans[yy_current_state];" );
  669.         indent_puts( "yy_is_jam = (yy_current_state == 0);" );
  670.         }
  671.  
  672.     else if ( fulltbl )
  673.         {
  674.         do_indent();
  675.         printf( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
  676.             NUL_ec );
  677.         indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
  678.         }
  679.  
  680.     else if ( fullspd )
  681.         {
  682.         do_indent();
  683.         printf( "register int yy_c = %d;\n", NUL_ec );
  684.  
  685.         indent_puts(
  686.         "register const struct yy_trans_info *yy_trans_info;\n" );
  687.         indent_puts(
  688.         "yy_trans_info = &yy_current_state[(unsigned int) yy_c];" );
  689.         indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
  690.  
  691.         indent_puts(
  692.             "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
  693.         }
  694.  
  695.     else
  696.         {
  697.         char NUL_ec_str[20];
  698.  
  699.         (void) sprintf( NUL_ec_str, "%d", NUL_ec );
  700.         gen_next_compressed_state( NUL_ec_str );
  701.  
  702.         if ( reject )
  703.             indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  704.  
  705.         do_indent();
  706.  
  707.         printf( "yy_is_jam = (yy_current_state == %d);\n", jamstate );
  708.         }
  709.  
  710.     /* If we've entered an accepting state, back up; note that
  711.      * compressed tables have *already* done such backing up, so
  712.      * we needn't bother with it again.
  713.      */
  714.     if ( need_backing_up && (fullspd || fulltbl) )
  715.         {
  716.         putchar( '\n' );
  717.         indent_puts( "if ( ! yy_is_jam )" );
  718.         indent_up();
  719.         indent_puts( "{" );
  720.         gen_backing_up();
  721.         indent_puts( "}" );
  722.         indent_down();
  723.         }
  724.     }
  725.  
  726.  
  727. /* Generate the code to find the start state. */
  728.  
  729. void gen_start_state()
  730.     {
  731.     if ( fullspd )
  732.         indent_put2s(
  733.             "yy_current_state = yy_start_state_list[yy_start%s];",
  734.             bol_needed ? " + (yy_bp[-1] == '\\n' ? 1 : 0)" : "" );
  735.  
  736.     else
  737.         {
  738.         indent_puts( "yy_current_state = yy_start;" );
  739.  
  740.         if ( bol_needed )
  741.             {
  742.             indent_puts( "if ( yy_bp[-1] == '\\n' )" );
  743.             indent_up();
  744.             indent_puts( "++yy_current_state;" );
  745.             indent_down();
  746.             }
  747.  
  748.         if ( reject )
  749.             {
  750.             /* Set up for storing up states. */
  751.             indent_puts( "yy_state_ptr = yy_state_buf;" );
  752.             indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  753.             }
  754.         }
  755.     }
  756.  
  757.  
  758. /* gentabs - generate data statements for the transition tables */
  759.  
  760. void gentabs()
  761.     {
  762.     int i, j, k, *accset, nacc, *acc_array, total_states;
  763.     int end_of_buffer_action = num_rules + 1;
  764.  
  765.     /* *Everything* is done in terms of arrays starting at 1, so provide
  766.      * a null entry for the zero element of all C arrays.
  767.      */
  768.     static char C_char_decl[] =
  769.         "static const YY_CHAR %s[%d] =\n    {   0,\n";    /* } for vi */
  770.  
  771.     acc_array = allocate_integer_array( current_max_dfas );
  772.     nummt = 0;
  773.  
  774.     /* The compressed table format jams by entering the "jam state",
  775.      * losing information about the previous state in the process.
  776.      * In order to recover the previous state, we effectively need
  777.      * to keep backing-up information.
  778.      */
  779.     ++num_backing_up;
  780.  
  781.     if ( reject )
  782.         {
  783.         /* Write out accepting list and pointer list.
  784.          *
  785.          * First we generate the "yy_acclist" array.  In the process,
  786.          * we compute the indices that will go into the "yy_accept"
  787.          * array, and save the indices in the dfaacc array.
  788.          */
  789.         int EOB_accepting_list[2];
  790.  
  791.         /* Set up accepting structures for the End Of Buffer state. */
  792.         EOB_accepting_list[0] = 0;
  793.         EOB_accepting_list[1] = end_of_buffer_action;
  794.         accsiz[end_of_buffer_state] = 1;
  795.         dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list;
  796.  
  797.         printf( long_align ? C_long_decl : C_short_decl,
  798.             "yy_acclist", MAX( numas, 1 ) + 1 );
  799.  
  800.         j = 1;    /* index into "yy_acclist" array */
  801.  
  802.         for ( i = 1; i <= lastdfa; ++i )
  803.             {
  804.             acc_array[i] = j;
  805.  
  806.             if ( accsiz[i] != 0 )
  807.                 {
  808.                 accset = dfaacc[i].dfaacc_set;
  809.                 nacc = accsiz[i];
  810.  
  811.                 if ( trace )
  812.                     fprintf( stderr,
  813.                         "state # %d accepts: ", i );
  814.  
  815.                 for ( k = 1; k <= nacc; ++k )
  816.                     {
  817.                     int accnum = accset[k];
  818.  
  819.                     ++j;
  820.  
  821.                     if ( variable_trailing_context_rules &&
  822.                       ! (accnum & YY_TRAILING_HEAD_MASK) &&
  823.                        accnum > 0 && accnum <= num_rules &&
  824.                       rule_type[accnum] == RULE_VARIABLE )
  825.                         {
  826.                         /* Special hack to flag
  827.                          * accepting number as part
  828.                          * of trailing context rule.
  829.                          */
  830.                         accnum |= YY_TRAILING_MASK;
  831.                         }
  832.  
  833. #ifdef MPW
  834.                     SpinCursor( 1 );
  835. #endif
  836.                     mkdata( accnum );
  837.  
  838.                     if ( trace )
  839.                         {
  840.                         fprintf( stderr, "[%d]",
  841.                             accset[k] );
  842.  
  843.                         if ( k < nacc )
  844.                             fputs( ", ", stderr );
  845.                         else
  846.                             putc( '\n', stderr );
  847.                         }
  848.                     }
  849.                 }
  850.             }
  851.  
  852.         /* add accepting number for the "jam" state */
  853.         acc_array[i] = j;
  854.  
  855.         dataend();
  856.         }
  857.  
  858.     else
  859.         {
  860.         dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
  861.  
  862.         for ( i = 1; i <= lastdfa; ++i )
  863.             acc_array[i] = dfaacc[i].dfaacc_state;
  864.  
  865.         /* add accepting number for jam state */
  866.         acc_array[i] = 0;
  867.         }
  868.  
  869.     /* Spit out "yy_accept" array.  If we're doing "reject", it'll be
  870.      * pointers into the "yy_acclist" array.  Otherwise it's actual
  871.      * accepting numbers.  In either case, we just dump the numbers.
  872.      */
  873.  
  874.     /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
  875.      * beginning at 0 and for "jam" state.
  876.      */
  877.     k = lastdfa + 2;
  878.  
  879.     if ( reject )
  880.         /* We put a "cap" on the table associating lists of accepting
  881.          * numbers with state numbers.  This is needed because we tell
  882.          * where the end of an accepting list is by looking at where
  883.          * the list for the next state starts.
  884.          */
  885.         ++k;
  886.  
  887.     printf( long_align ? C_long_decl : C_short_decl, "yy_accept", k );
  888.  
  889.     for ( i = 1; i <= lastdfa; ++i )
  890.         {
  891.         mkdata( acc_array[i] );
  892.  
  893. #ifdef MPW
  894.         SpinCursor( 1 );
  895. #endif
  896.         if ( ! reject && trace && acc_array[i] )
  897.             fprintf( stderr, "state # %d accepts: [%d]\n",
  898.                 i, acc_array[i] );
  899.         }
  900.  
  901.     /* Add entry for "jam" state. */
  902.     mkdata( acc_array[i] );
  903.  
  904.     if ( reject )
  905.         /* Add "cap" for the list. */
  906.         mkdata( acc_array[i] );
  907.  
  908.     dataend();
  909.  
  910.     if ( useecs )
  911.         genecs();
  912.  
  913.     if ( usemecs )
  914.         {
  915.         /* Write out meta-equivalence classes (used to index
  916.          * templates with).
  917.          */
  918.  
  919.         if ( trace )
  920.             fputs( "\n\nMeta-Equivalence Classes:\n", stderr );
  921.  
  922.         printf( C_int_decl, "yy_meta", numecs + 1 );
  923.  
  924.         for ( i = 1; i <= numecs; ++i )
  925.             {
  926.             if ( trace )
  927.                 fprintf( stderr, "%d = %d\n",
  928.                     i, ABS( tecbck[i] ) );
  929.  
  930. #ifdef MPW
  931.             SpinCursor( 1 );
  932. #endif
  933.             mkdata( ABS( tecbck[i] ) );
  934.             }
  935.  
  936.         dataend();
  937.         }
  938.  
  939.     total_states = lastdfa + numtemps;
  940.  
  941.     printf( (tblend >= MAX_SHORT || long_align) ?
  942.             C_long_decl : C_short_decl,
  943.         "yy_base", total_states + 1 );
  944.  
  945.     for ( i = 1; i <= lastdfa; ++i )
  946.         {
  947.         register int d = def[i];
  948.  
  949.         if ( base[i] == JAMSTATE )
  950.             base[i] = jambase;
  951.  
  952.         if ( d == JAMSTATE )
  953.             def[i] = jamstate;
  954.  
  955.         else if ( d < 0 )
  956.             {
  957.             /* Template reference. */
  958.             ++tmpuses;
  959.             def[i] = lastdfa - d + 1;
  960.             }
  961.  
  962.         mkdata( base[i] );
  963. #ifdef MPW
  964.         SpinCursor( 1 );
  965. #endif
  966.         }
  967.  
  968.     /* Generate jam state's base index. */
  969.     mkdata( base[i] );
  970.  
  971.     for ( ++i /* skip jam state */; i <= total_states; ++i )
  972.         {
  973.         mkdata( base[i] );
  974.         def[i] = jamstate;
  975.         }
  976.  
  977.     dataend();
  978.  
  979.     printf( (total_states >= MAX_SHORT || long_align) ?
  980.             C_long_decl : C_short_decl,
  981.         "yy_def", total_states + 1 );
  982.  
  983.     for ( i = 1; i <= total_states; ++i )
  984.         mkdata( def[i] );
  985.  
  986. #ifdef MPW
  987.     SpinCursor( 1 );
  988. #endif
  989.     dataend();
  990.  
  991.     printf( (total_states >= MAX_SHORT || long_align) ?
  992.             C_long_decl : C_short_decl,
  993.         "yy_nxt", tblend + 1 );
  994.  
  995.     for ( i = 1; i <= tblend; ++i )
  996.         {
  997.         if ( nxt[i] == 0 || chk[i] == 0 )
  998.             nxt[i] = jamstate;    /* new state is the JAM state */
  999.  
  1000.         mkdata( nxt[i] );
  1001.         }
  1002.  
  1003.     dataend();
  1004.  
  1005.     printf( (total_states >= MAX_SHORT || long_align) ?
  1006.             C_long_decl : C_short_decl,
  1007.         "yy_chk", tblend + 1 );
  1008.  
  1009.     for ( i = 1; i <= tblend; ++i )
  1010.         {
  1011.         if ( chk[i] == 0 )
  1012.             ++nummt;
  1013.  
  1014.         mkdata( chk[i] );
  1015. #ifdef MPW
  1016.         SpinCursor( 1 );
  1017. #endif
  1018.         }
  1019.  
  1020.     dataend();
  1021.     }
  1022.  
  1023.  
  1024. /* Write out a formatted string (with a secondary string argument) at the
  1025.  * current indentation level, adding a final newline.
  1026.  */
  1027.  
  1028. void indent_put2s( fmt, arg )
  1029. char fmt[], arg[];
  1030.     {
  1031.     do_indent();
  1032.     printf( fmt, arg );
  1033.     putchar( '\n' );
  1034.     }
  1035.  
  1036.  
  1037. /* Write out a string at the current indentation level, adding a final
  1038.  * newline.
  1039.  */
  1040.  
  1041. void indent_puts( str )
  1042. char str[];
  1043.     {
  1044.     do_indent();
  1045.     puts( str );
  1046.     }
  1047.  
  1048.  
  1049. /* make_tables - generate transition tables and finishes generating output file
  1050.  */
  1051.  
  1052. void make_tables()
  1053.     {
  1054.     register int i;
  1055.     int did_eof_rule = false;
  1056.  
  1057.     skelout();
  1058.  
  1059.     /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
  1060.      * being used.
  1061.      */
  1062.     set_indent( 1 );
  1063.  
  1064.     if ( yymore_used )
  1065.         {
  1066.         indent_puts( "yytext_ptr -= yy_more_len; \\" );
  1067.         indent_puts( "yyleng = yy_cp - yytext_ptr; \\" );
  1068.         }
  1069.  
  1070.     else
  1071.         indent_puts( "yyleng = yy_cp - yy_bp; \\" );
  1072.  
  1073.     /* Now also deal with copying yytext_ptr to yytext if needed. */
  1074.     skelout();
  1075.     if ( yytext_is_array )
  1076.         {
  1077.         indent_puts( "if ( yyleng >= YYLMAX ) \\" );
  1078.         indent_up();
  1079.         indent_puts(
  1080.         "YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" );
  1081.         indent_down();
  1082.         indent_puts( "yy_flex_strcpy( yytext, yytext_ptr ); \\" );
  1083.         }
  1084.  
  1085.     set_indent( 0 );
  1086.  
  1087.     skelout();
  1088.  
  1089.  
  1090.     printf( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );
  1091.  
  1092.     if ( fullspd )
  1093.         {
  1094.         /* Need to define the transet type as a size large
  1095.          * enough to hold the biggest offset.
  1096.          */
  1097.         int total_table_size = tblend + numecs + 1;
  1098.         char *trans_offset_type =
  1099.             (total_table_size >= MAX_SHORT || long_align) ?
  1100.                 "long" : "short";
  1101.  
  1102.         set_indent( 0 );
  1103.         indent_puts( "struct yy_trans_info" );
  1104.         indent_up();
  1105.         indent_puts( "{" );     /* } for vi */
  1106.  
  1107.         if ( long_align )
  1108.             indent_puts( "long yy_verify;" );
  1109.         else
  1110.             indent_puts( "short yy_verify;" );
  1111.  
  1112.         /* In cases where its sister yy_verify *is* a "yes, there is
  1113.          * a transition", yy_nxt is the offset (in records) to the
  1114.          * next state.  In most cases where there is no transition,
  1115.          * the value of yy_nxt is irrelevant.  If yy_nxt is the -1th
  1116.          * record of a state, though, then yy_nxt is the action number
  1117.          * for that state.
  1118.          */
  1119.  
  1120.         indent_put2s( "%s yy_nxt;", trans_offset_type );
  1121.         indent_puts( "};" );
  1122.         indent_down();
  1123.         }
  1124.  
  1125.     if ( fullspd )
  1126.         genctbl();
  1127.     else if ( fulltbl )
  1128.         genftbl();
  1129.     else
  1130.         gentabs();
  1131.  
  1132.     /* Definitions for backing up.  We don't need them if REJECT
  1133.      * is being used because then we use an alternative backin-up
  1134.      * technique instead.
  1135.      */
  1136.     if ( num_backing_up > 0 && ! reject )
  1137.         {
  1138.         if ( ! C_plus_plus )
  1139.             {
  1140.             indent_puts(
  1141.             "static yy_state_type yy_last_accepting_state;" );
  1142.             indent_puts(
  1143.                 "static char *yy_last_accepting_cpos;\n" );
  1144.             }
  1145.         }
  1146.  
  1147.     if ( nultrans )
  1148.         {
  1149.         printf( C_state_decl, "yy_NUL_trans", lastdfa + 1 );
  1150.  
  1151.         for ( i = 1; i <= lastdfa; ++i )
  1152.             {
  1153.             if ( fullspd )
  1154.                 printf( "    &yy_transition[%d],\n", base[i] );
  1155.             else
  1156.                 mkdata( nultrans[i] );
  1157.             }
  1158.  
  1159.         dataend();
  1160.         }
  1161.  
  1162.     if ( ddebug )
  1163.         { /* Spit out table mapping rules to line numbers. */
  1164.         indent_puts( "extern int yy_flex_debug;" );
  1165.         indent_puts( "int yy_flex_debug = 1;\n" );
  1166.  
  1167.         printf( long_align ? C_long_decl : C_short_decl,
  1168.             "yy_rule_linenum", num_rules );
  1169.         for ( i = 1; i < num_rules; ++i )
  1170.             mkdata( rule_linenum[i] );
  1171.         dataend();
  1172.         }
  1173.  
  1174.     if ( reject )
  1175.         {
  1176.         /* Declare state buffer variables. */
  1177.         if ( ! C_plus_plus )
  1178.             {
  1179.             puts(
  1180.     "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
  1181.             puts( "static char *yy_full_match;" );
  1182.             puts( "static int yy_lp;" );
  1183.             }
  1184.  
  1185.         if ( variable_trailing_context_rules )
  1186.             {
  1187.             if ( ! C_plus_plus )
  1188.                 {
  1189.                 puts(
  1190.                 "static int yy_looking_for_trail_begin = 0;" );
  1191.                 puts( "static int yy_full_lp;" );
  1192.                 puts( "static int *yy_full_state;" );
  1193.                 }
  1194.  
  1195.             printf( "#define YY_TRAILING_MASK 0x%x\n",
  1196.                 (unsigned int) YY_TRAILING_MASK );
  1197.             printf( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
  1198.                 (unsigned int) YY_TRAILING_HEAD_MASK );
  1199.             }
  1200.  
  1201.         puts( "#define REJECT \\" );
  1202.         puts( "{ \\" );        /* } for vi */
  1203.         puts(
  1204.     "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
  1205.         puts(
  1206.     "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
  1207.  
  1208.         if ( variable_trailing_context_rules )
  1209.             {
  1210.             puts(
  1211.         "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
  1212.             puts(
  1213.         "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
  1214.             puts(
  1215.     "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
  1216.             }
  1217.  
  1218.         puts( "++yy_lp; \\" );
  1219.         puts( "goto find_rule; \\" );
  1220.         /* { for vi */
  1221.         puts( "}" );
  1222.         }
  1223.  
  1224.     else
  1225.         {
  1226.         puts(
  1227.         "/* The intent behind this definition is that it'll catch" );
  1228.         puts( " * any uses of REJECT which flex missed." );
  1229.         puts( " */" );
  1230.         puts( "#define REJECT reject_used_but_not_detected" );
  1231.         }
  1232.  
  1233.     if ( yymore_used )
  1234.         {
  1235.         if ( ! C_plus_plus )
  1236.             {
  1237.             indent_puts( "static int yy_more_flag = 0;" );
  1238.             indent_puts( "static int yy_more_len = 0;" );
  1239.             }
  1240.  
  1241.         indent_puts( "#define yymore() (yy_more_flag = 1)" );
  1242.         indent_puts( "#define YY_MORE_ADJ yy_more_len" );
  1243.         }
  1244.  
  1245.     else
  1246.         {
  1247.         indent_puts( "#define yymore() yymore_used_but_not_detected" );
  1248.         indent_puts( "#define YY_MORE_ADJ 0" );
  1249.         }
  1250.  
  1251.     if ( ! C_plus_plus )
  1252.         {
  1253.         if ( yytext_is_array )
  1254.             {
  1255.             puts( "#ifndef YYLMAX" );
  1256.             puts( "#define YYLMAX 8192" );
  1257.             puts( "#endif\n" );
  1258.             puts( "char yytext[YYLMAX];" );
  1259.             puts( "char *yytext_ptr;" );
  1260.             }
  1261.  
  1262.         else
  1263.             puts( "char *yytext;" );
  1264.         }
  1265.  
  1266.     fputs( &action_array[defs1_offset], stdout );
  1267.  
  1268.     skelout();
  1269.  
  1270.     if ( ! C_plus_plus )
  1271.         {
  1272.         if ( use_read )
  1273.             {
  1274.             printf(
  1275. "\tif ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\\n" );
  1276.             printf(
  1277.         "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );\n" );
  1278.             }
  1279.  
  1280.         else
  1281.             {
  1282.             printf(
  1283.             "\tif ( yy_current_buffer->yy_is_interactive ) \\\n" );
  1284.             printf( "\t\t{ \\\n" );
  1285.             printf( "\t\tint c = getc( yyin ); \\\n" );
  1286.             printf( "\t\tresult = c == EOF ? 0 : 1; \\\n" );
  1287.             printf( "\t\tbuf[0] = (char) c; \\\n" );
  1288.             printf( "\t\t} \\\n" );
  1289.             printf(
  1290.     "\telse if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \\\n" );
  1291.             printf( "\t\t  && ferror( yyin ) ) \\\n" );
  1292.             printf(
  1293.         "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );\n" );
  1294.             }
  1295.         }
  1296.  
  1297.     skelout();
  1298.  
  1299.     /* Copy prolog to output file. */
  1300.     fputs( &action_array[prolog_offset], stdout );
  1301.  
  1302.     skelout();
  1303.  
  1304.     set_indent( 2 );
  1305.  
  1306.     if ( yymore_used )
  1307.         {
  1308.         indent_puts( "yy_more_len = 0;" );
  1309.         indent_puts( "if ( yy_more_flag )" );
  1310.         indent_up();
  1311.         indent_puts( "{" );
  1312.         indent_puts( "yy_more_len = yyleng;" );
  1313.         indent_puts( "yy_more_flag = 0;" );
  1314.         indent_puts( "}" );
  1315.         indent_down();
  1316.         }
  1317.  
  1318.     skelout();
  1319.  
  1320.     gen_start_state();
  1321.  
  1322.     /* Note, don't use any indentation. */
  1323.     puts( "yy_match:" );
  1324.     gen_next_match();
  1325.  
  1326.     skelout();
  1327.     set_indent( 2 );
  1328.     gen_find_action();
  1329.  
  1330.     skelout();
  1331.     if ( lex_compat )
  1332.         {
  1333.         indent_puts( "if ( yy_act != YY_END_OF_BUFFER )" );
  1334.         indent_up();
  1335.         indent_puts( "{" );
  1336.         indent_puts( "int yyl;" );
  1337.         indent_puts( "for ( yyl = 0; yyl < yyleng; ++yyl )" );
  1338.         indent_up();
  1339.         indent_puts( "if ( yytext[yyl] == '\\n' )" );
  1340.         indent_up();
  1341.         indent_puts( "++yylineno;" );
  1342.         indent_down();
  1343.         indent_down();
  1344.         indent_puts( "}" );
  1345.         indent_down();
  1346.         }
  1347.  
  1348.     skelout();
  1349.     if ( ddebug )
  1350.         {
  1351.         indent_puts( "if ( yy_flex_debug )" );
  1352.         indent_up();
  1353.  
  1354.         indent_puts( "{" );
  1355.         indent_puts( "if ( yy_act == 0 )" );
  1356.         indent_up();
  1357.         indent_puts(
  1358.             "fprintf( stderr, \"--scanner backing up\\n\" );" );
  1359.         indent_down();
  1360.  
  1361.         do_indent();
  1362.         printf( "else if ( yy_act < %d )\n", num_rules );
  1363.         indent_up();
  1364.         indent_puts(
  1365.     "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
  1366.         indent_puts( "         yy_rule_linenum[yy_act], yytext );" );
  1367.         indent_down();
  1368.  
  1369.         do_indent();
  1370.         printf( "else if ( yy_act == %d )\n", num_rules );
  1371.         indent_up();
  1372.         indent_puts(
  1373.     "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
  1374.         indent_puts( "         yytext );" );
  1375.         indent_down();
  1376.  
  1377.         do_indent();
  1378.         printf( "else if ( yy_act == %d )\n", num_rules + 1 );
  1379.         indent_up();
  1380.         indent_puts(
  1381.     "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
  1382.         indent_down();
  1383.  
  1384.         do_indent();
  1385.         printf( "else\n" );
  1386.         indent_up();
  1387.         indent_puts(
  1388.     "fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );" );
  1389.         indent_down();
  1390.  
  1391.         indent_puts( "}" );
  1392.         indent_down();
  1393.         }
  1394.  
  1395.     /* Copy actions to output file. */
  1396.     skelout();
  1397.     indent_up();
  1398.     gen_bu_action();
  1399.     fputs( &action_array[action_offset], stdout );
  1400.  
  1401.     /* generate cases for any missing EOF rules */
  1402.     for ( i = 1; i <= lastsc; ++i )
  1403.         if ( ! sceof[i] )
  1404.             {
  1405.             do_indent();
  1406.             printf( "case YY_STATE_EOF(%s):\n", scname[i] );
  1407.             did_eof_rule = true;
  1408.             }
  1409.  
  1410.     if ( did_eof_rule )
  1411.         {
  1412.         indent_up();
  1413.         indent_puts( "yyterminate();" );
  1414.         indent_down();
  1415.         }
  1416.  
  1417.  
  1418.     /* Generate code for handling NUL's, if needed. */
  1419.  
  1420.     /* First, deal with backing up and setting up yy_cp if the scanner
  1421.      * finds that it should JAM on the NUL>
  1422.      */
  1423.     skelout();
  1424.     set_indent( 7 );
  1425.  
  1426.     if ( fullspd || fulltbl )
  1427.         indent_puts( "yy_cp = yy_c_buf_p;" );
  1428.  
  1429.     else
  1430.         { /* compressed table */
  1431.         if ( ! reject && ! interactive )
  1432.             {
  1433.             /* Do the guaranteed-needed backing up to figure
  1434.              * out the match.
  1435.              */
  1436.             indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  1437.             indent_puts(
  1438.                 "yy_current_state = yy_last_accepting_state;" );
  1439.             }
  1440.         }
  1441.  
  1442.  
  1443.     /* Generate code for yy_get_previous_state(). */
  1444.     set_indent( 1 );
  1445.     skelout();
  1446.  
  1447.     if ( bol_needed )
  1448.         indent_puts( "register char *yy_bp = yytext_ptr;\n" );
  1449.  
  1450.     gen_start_state();
  1451.  
  1452.     set_indent( 2 );
  1453.     skelout();
  1454.     gen_next_state( true );
  1455.  
  1456.     set_indent( 1 );
  1457.     skelout();
  1458.     gen_NUL_trans();
  1459.  
  1460.     skelout();
  1461.     if ( lex_compat )
  1462.         { /* update yylineno inside of unput() */
  1463.         indent_puts( "if ( c == '\\n' )" );
  1464.         indent_up();
  1465.         indent_puts( "--yylineno;" );
  1466.         indent_down();
  1467.         }
  1468.  
  1469.     skelout();
  1470.  
  1471.     /* Copy remainder of input to output. */
  1472.  
  1473.     line_directive_out( stdout );
  1474.  
  1475.     if ( sectnum == 3 )
  1476.         (void) flexscan(); /* copy remainder of input to output */
  1477.     }
  1478.